<?php

namespace app\admin\controller;

use think\App;
use think\Request;
use app\admin\services\ProblemService;
use app\admin\services\IndexService;
use think\facade\Session;

class Problem extends Authent
{
    public function __construct(Request $request = null, App $app = null)
    {
        parent::__construct($request, $app);
        $this->ProblemService = new ProblemService;
        $this->indexService = new IndexService;
        global $authstate;
        if(isset($authstate['status']) && $authstate['status'] !=0 ){
            echo alert_error("无访问权限!", "/admin/problem/index");
            exit();
        }

    }


    /**
     * @return mixed
     * 首页
     */
    public function index()
    {
        $uid = Session::get('uid','admin');
        $this->assign('userid',$uid);
        return $this->fetch();
    }


    /**
     * @问题列表数据
     */
    public function selecty(){
        $data = $this->ProblemService->lists();
        return json($data);
    }


    /**
     * @param 添加问题页面
     */
    public function addproble(){
        $data = $this->ProblemService->pridlist();
        $vers = $this->indexService->Version();
        $manid = $this->indexService->manaid();
        $this->assign('manid',$manid);
        $this->assign('vers',$vers);
        $this->assign("title",$data);
        return $this->fetch();
    }


    /**
     * @param 上传图片
     */
    public function ajaxUpload(){
        $data = $this->ProblemService->ajaxUpload();
        return json($data);
    }


    /**
     * @param 添加问题
     */
    public function add(){
        $data = $this->ProblemService->add();
        return json($data);
    }


    /**
     * @param 禁用/启用
     */
    public function jinyong(){
        $data = $this->ProblemService->examine();
        return json($data);
    }


    /**
     * @param 删除问题
     */
    public function del(){
        $data = $this->ProblemService->del();
        return json($data);
    }


    /**
     * @return mixed
     * @param 获取当前修改信息
     */
    public function edit(){
        $data = $this->ProblemService->eddata();
        $title = $this->ProblemService->pridlist();
        $vers = $this->indexService->Version();
        $manid = $this->indexService->manaid();
        $this->assign('manid',$manid);
        $this->assign('vers',$vers);
        $this->assign("data",$data);
        $this->assign("title",$title);
        return $this->fetch();
    }


    /**
     * @param 修改问题
     */
    public function editlist(){
        $data = $this->ProblemService->editonst();
        return json($data);
    }


    /**
     * @param 确认问题
     */
    public function confirm(){
        $data = $this->ProblemService->confirm();
        return json($data);
    }


    /**
     * @param 一键确认
     */
    public function deatr(){
        $data = $this->ProblemService->deatr();
        return json($data);
    }


    /**
     * @param 问题重置
     */
    public function restl(){
        $data = $this->ProblemService->restL();
        return json($data);
    }


    /**
     * @param 留言回复页面
     */
    public function auxiliar(){
        $data = $this->ProblemService->eddata();
        $userdata = $this->ProblemService->emaillist();
        $datas = $this->ProblemService->pkeion();
        $ltabe = $this->indexService->auxlist();
        $this->assign('ltabe',$ltabe);
        $this->assign('datas',$datas);
        $this->assign('userdata',$userdata);
        $this->assign('id',$data['id']);
        $this->assign('title',$data['title']);
        return $this->fetch();
    }


    /**
     * @param 提交留言
     */
    public function guestbook(){
        $data = $this->ProblemService->emailmomo();
        return json($data);
    }


    /**
     * @param 设置处理天数
     */
    public function groudtime(){
        $data = $this->ProblemService->groudtime();
        return json($data);
    }


    /**
     * @param 显示隐藏问题
     */
    public function showdata(){
        $data = $this->ProblemService->showdata();
        return json($data);
    }


    /**
     * @param 忽略问题
     */
    public function hule(){
        $data = $this->ProblemService->huledata();
        return json($data);
    }
}